package com.example.testrecorder.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.testrecorder.R;
import com.example.testrecorder.domain.QueAndAns;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yingyong Lao
 * 创建时间 2021/6/12 20:05
 * @version 1.0
 */
public class QueAndAnsAdapter extends BaseAdapter {
    private List<QueAndAns> list=new ArrayList<>();

    public QueAndAnsAdapter(List<QueAndAns> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        QueAndAns queAndAns = list.get(position);
        ViewHolder viewHolder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(parent.getContext()).inflate(R.layout.que_an_item,parent,false);
            viewHolder=new ViewHolder();
            viewHolder.idTv=convertView.findViewById(R.id.idTv);
            viewHolder.userIdTv=convertView.findViewById(R.id.userIdTv);
            viewHolder.questionTv=convertView.findViewById(R.id.questionTv);
            viewHolder.answerTv=convertView.findViewById(R.id.answerTv);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.idTv.setText(""+queAndAns.getId());
        viewHolder.userIdTv.setText(""+queAndAns.getUser_id());
        viewHolder.questionTv.setText(queAndAns.getQuestion());
        viewHolder.answerTv.setText(queAndAns.getAnswer());
        return convertView;
    }
    static class ViewHolder{
        TextView idTv,userIdTv,questionTv,answerTv;
    }
}
